2020-2021 Sunseeker Telemetry and Lighting System
adc12_b_ex3_extRef.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430FR59xx Demo - ADC12B, Using an External Reference
34 //
35 // Description: This example shows how to use an external positive reference for
36 // the ADC12B. The external reference is applied to the VeREF+ pin. AVss is used
37 // for the negative reference. A single conversion is performed on channel A0.
38 // The conversion results are stored in ADC12BMEM0 and Test by applying a voltage
39 // to channel A0, then setting and running to a break point at the "_NOP()"
40 // instruction. To view the conversion results, open an SFR window in debugger
41 // and view the contents of ADC12BMEM0.
42 // NOTE: VeREF+ range: 1.4V (min) to AVCC (max)
43 // VeREF- range: 0V (min) to 1.2V (max)
44 // Differential ref voltage range: 1.4V(min) to AVCC(max)
45 // (see datasheet for device specific information)
46 //
47 //
48 // MSP430FR5969
49 // -------------------
50 // /|\| |
51 // | | |
52 // --|RST |
53 // | |
54 // Vin -->|P1.0/A0 |
55 // | |
56 // REF -->|P1.1/VREF+/VeREF+ |
57 // | |
58 //
59 //******************************************************************************
60 #include "driverlib.h"
61 
62 void main(void)
63 {
64  // Stop WDT
65  WDT_A_hold(WDT_A_BASE);
66 
67  //Set P1.0 as Ternary Module Function Output.
68  /*
69 
70  * Select Port 1
71  * Set Pin 0 to output Ternary Module Function, (A0, C0, VREF-, VeREF-).
72  */
73  GPIO_setAsPeripheralModuleFunctionInputPin(
74  GPIO_PORT_P1,
75  GPIO_PIN0,
76  GPIO_TERNARY_MODULE_FUNCTION
77  );
78 
79  /*
80  * Disable the GPIO power-on default high-impedance mode to activate
81  * previously configured port settings
82  */
83  PMM_unlockLPM5();
84 
85  //Initialize the ADC12B Module
86  /*
87  * Base address of ADC12B Module
88  * Use internal ADC12B bit as sample/hold signal to start conversion
89  * USE MODOSC 5MHZ Digital Oscillator as clock source
90  * Use default clock divider/pre-divider of 1
91  * Not use internal channel
92  */
93  ADC12_B_initParam initParam = {0};
94  initParam.sampleHoldSignalSourceSelect = ADC12_B_SAMPLEHOLDSOURCE_SC;
95  initParam.clockSourceSelect = ADC12_B_CLOCKSOURCE_ADC12OSC;
96  initParam.clockSourceDivider = ADC12_B_CLOCKDIVIDER_1;
97  initParam.clockSourcePredivider = ADC12_B_CLOCKPREDIVIDER__1;
98  initParam.internalChannelMap = ADC12_B_NOINTCH;
99  ADC12_B_init(ADC12_B_BASE, &initParam);
100 
101  //Enable the ADC12B module
102  ADC12_B_enable(ADC12_B_BASE);
103 
104  /*
105  * Base address of ADC12B Module
106  * For memory buffers 0-7 sample/hold for 16 clock cycles
107  * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
108  * Disable Multiple Sampling
109  */
110  ADC12_B_setupSamplingTimer(ADC12_B_BASE,
111  ADC12_B_CYCLEHOLD_16_CYCLES,
112  ADC12_B_CYCLEHOLD_4_CYCLES,
113  ADC12_B_MULTIPLESAMPLESDISABLE);
114 
115  //Configure Memory Buffer
116  /*
117  * Base address of the ADC12B Module
118  * Configure memory buffer 0
119  * Map input A0 to memory buffer 0
120  * Vref+ = AVcc
121  * Vref- = EXT Positive
122  * Memory buffer 0 is not the end of a sequence
123  */
124  ADC12_B_configureMemoryParam configureMemoryParam = {0};
125  configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_0;
126  configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A0;
127  configureMemoryParam.refVoltageSourceSelect = ADC12_B_VREFPOS_EXTPOS_VREFNEG_VSS;
128  configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
129  configureMemoryParam.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;
130  configureMemoryParam.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;
131  ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);
132 
133  while (1)
134  {
135  //Enable/Start first sampling and conversion cycle
136  /*
137  * Base address of ADC12B Module
138  * Start the conversion into memory buffer 0
139  * Use the single-channel, single-conversion mode
140  */
141  ADC12_B_startConversion(ADC12_B_BASE,
142  ADC12_B_MEMORY_0,
143  ADC12_B_SINGLECHANNEL);
144 
145  //Poll for interrupt on memory buffer 0
146  while (!ADC12_B_getInterruptStatus(ADC12_B_BASE,
147  0,
148  ADC12_B_IFG0));
149 
150  __no_operation(); // SET BREAKPOINT HERE
151  }
152 }
void main(void)
__no_operation()